package com.xdu.math.Service;

import org.springframework.stereotype.Service;
import com.xdu.math.Entity.SquareMatrix;
import com.xdu.math.Util.InvalidInputException;

@Service
public class DeterminantService {
    public Float calculateDeterminant2x2(SquareMatrix d2) throws Exception{
        if(d2.getA() == null) throw new InvalidInputException("Determinant2.A is null");
        if(d2.getB() == null) throw new InvalidInputException("Determinant2.B is null");
        if(d2.getC() == null) throw new InvalidInputException("Determinant2.C is null");
        if(d2.getD() == null) throw new InvalidInputException("Determinant2.D is null");
        return d2.getA()*d2.getC() - d2.getB()*d2.getD() >= 0 ? d2.getA()*d2.getC() - d2.getB()*d2.getD():d2.getB()*d2.getD() - d2.getA()*d2.getC();
    }
}
